草庐IT

Android::Extending MapActivity => classNotFound 异常

全部标签

c# - 如果列表/集合为空或 null 且无法迭代(不是参数),抛出什么异常类型?

假设一个简单的例子,其中一个方法检索一个集合(例如包含一些配置字符串的列表)并尝试以某种方式检查它:voidInit(){XmlDocumentconfig=newXmlDocument();config.Load(someXml);varlist=config.SelectNodes("/root/strings/key");//Normally,listshouldnotbenulloremptyif(list==null||list.Count==0)thrownewSomeExceptionType(message);//Whatkindofexceptiontothrow?/

c# - 使用后期绑定(bind)获取 List<T> 值

我有一个List变量,其中T在编译时未知。我需要访问value类型属性T像这样foreach(variteminitems)//itemsisList{item.value//thiswon'tcompilebecauseTisunknown}我知道在我的例子中会有value属性(property)。我怎样才能访问它? 最佳答案 如果您知道每个T都有VALUE,您可以使用dynamic而不是varforeach(dynamiciteminitems)//itemsisList{item.VALUE}

c# - C# 中的 EventHandler<TEventArgs> 线程安全?

使用我自定义的EventArgs例如:publiceventEventHandlerSampleEvent;来自msdn例如:publicclassHasEvent{//DeclareaneventofdelegatetypeEventHandlerof//MyEventArgs.publiceventEventHandlerSampleEvent;publicvoidDemoEvent(stringval){//Copytoatemporaryvariabletobethread-safe.EventHandlertemp=SampleEvent;if(temp!=null)temp

c# - 为什么 List<T> 出现 "Index was out of range"异常而不是数组?

当我初始化数组并使用索引器访问元素时,效果很好:object[]temp=newobject[5];temp[0]="bar";现在我希望同样适用于List,假设您可以通过将容量传递给构造函数来初始化它:Listtemp=newList(5);temp[0]="bar";然而,最后一行抛出以下异常:Indexwasoutofrange.Mustbenon-negativeandlessthanthesizeofthecollection为什么List会发生这种情况类型,但不是数组?由于数组只是CLR集合的较低级别抽象,那么为什么会出现此异常?原创question通过AwaisMahmo

c# - 为什么不能使用 is 运算符来区分 bool 和 Nullable<bool>?

我遇到了这个,很好奇为什么不能使用is运算符区分bool和Nullable?示例;voidMain(){booltheBool=false;NullabletheNullableBoolThatsFalse=false;NullabletheNullableBoolThatsNull=null;voidWhatIsIt(objectvalue){if(valueisbool)Console.WriteLine("It'sabool!");if(valueisNullable)Console.WriteLine("It'saNullable!");if(valueisnull)Conso

c# - 无法将 IQueryable<> 转换为 IOrderedQueryable 错误

我有以下LINQ代码:varposts=(frompindb.Posts.Include("Site").Include("PostStatus")wherep.Public==falseorderbyp.PublicationTimeselectp);if(!chkShowIgnored.Checked){posts=posts.Where(p=>p.PostStatus.Id!=90);}最后一行(额外的地方)给我错误:无法将类型“System.Linq.IQueryable”隐式转换为“System.Linq.IOrderedQueryable”。我不确定这是什么意思...为什么

c# - 如何序列化 IList<T> 等接口(interface)

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:HowtoserializeanIList?我希望序列化一个包含S类型属性的类(我们称之为IList)其中T是我定义的另一个类。当我尝试序列化类S的实例时出现异常到XML。这可以理解为XmlSerializer不知道要使用哪个具体类。有没有一种方法,希望使用属性,来指定在序列化/反序列化实例时实例化哪个具体类。我的类(class)实现S创建List的实例类(class)。下面是一些代码来说明我的示例:usingSystem;usingSystem.Xml.Serialization;usingSystem.I

c# - GetAuthorizationGroups() 抛出异常

PrincipalContextcontext=newPrincipalContext(ContextType.Domain,"ipofmachine","DC=xyz,DC=org","username","Password");UserPrincipaluserPrinciple=UserPrincipal.FindByIdentity(context,"User0");vargroups=userPrinciple.GetAuthorizationGroups();if(userPrinciple!=null){foreach(GroupPrincipalgpingroups){

c# - 异步任务<IEnumerable<T>> 抛出 "is not an iterator interface type"错误

仅当我使用async时,下面的代码才会抛出isnotaniteratorinterfacetypeawait并包装IEnumerable与任务。如果我删除asyncawait,它将与IEnumerable>一起使用.privateasyncTask>>GetTableDataAsync(CloudTablecloudTable,TableQuerytableQuery)whereT:ITableEntity,new(){TableContinuationTokencontineousToken=null;do{varcurrentSegment=awaitGetAzureTableDa

c# - MSBuild 未处理的异常 : The FileName property should not be a directory unless UseShellExecute is set

版本dotnet核心SDK:2.1.403docker:18.09.7Linux内核:5.0.0-27Ubuntu:18.04.3问题我正在docker中运行一个ASP.NETCore项目。当我docker-composeup时,我得到以下信息:UnhandledException:Microsoft.Build.BackEnd.NodeFailedToLaunchException:TheFileNamepropertyshouldnotbeadirectoryunlessUseShellExecuteisset.--->System.ComponentModel.Win32Exce